/*公共前后台数据*/
var sys_exploer = navigator.appName == "Microsoft Internet Explorer" ? "IE" : "FF";
var str_right = '<span style="color:darkblue;">&#8730;</span>';
var str_wrong = '<span style="color:darkred;">&#215;</span>';
var doc_type = (document.documentElement) ? document.documentElement : document.body;

/*通过JS生成URL信息，仅限动态数据*/
function get_url(cfd,extend)
{
	if(!base_url || !base_ctrl || !base_func || !base_dir)
	{
		return false;
	}
	if(!cfd || cfd == "undefined")
	{
		return base_url;
	}
	var url = base_file + "?";
	var array = cfd.split(",");
	if(array[0] && array[0] != "undefined")
	{
		url += base_ctrl + "=" + encode_utf8(array[0]) + "&";
	}
	if(array[1] && array[1] != "undefined")
	{
		url += base_func + "=" + encode_utf8(array[1]) + "&";
	}
	if(array[2] && array[2] != "undefined")
	{
		url += base_dir + "=" + encode_utf8(array[2]) + "&";
	}
	if(extend && extend != "undefined")
	{
		url += extend + "&";
	}
	return url;
}

//使用短函数getid替代 document.getElementById
function getid(id)
{
	return document.getElementById(id);
}

function getform(formid,id)
{
	if(!formid || formid == "undefined")
	{
		formid = "form";
	}
	return document.forms[formid].elements[id];
}

//按需加载JS文件以加快浏览速度
function js_load(url)
{
	var this_script = document.getElementsByTagName("script");
	for(i=0;i<this_script.length;i++)
	{
		if(this_script[i].src && this_script[i].src.indexOf(url)!=-1)
		{
			return true;
		}
	}
	var load_script = document.createElement("script");
	load_script.type = "text/javascript";
	load_script.src = url;
	var head=document.getElementsByTagName("head")[0];
	head.appendChild(load_script);
}

//按需加载CSS文件
function css_load(url)
{
	var this_style = document.getElementsByTagName("link");
	for(i=0;i<this_style.length;i++)
	{
		if(this_style[i].href && this_style[i].href.indexOf(url)!=-1)
		{
			return true;
		}
	}
	var load_style = document.createElement("link");
	load_style.type = "text/css";
	load_style.href = url;
	load_style.media = "all";
	load_style.rel = "stylesheet"
	var head=document.getElementsByTagName("head")[0];
	head.appendChild(load_style);
}

//预加载图片
function img_load(url,id)
{
	getid(id).src= url;
}

//定义跳转网址
//参数 url 要跳转的网址 frameid要跳转到的框架ID isparent是否是父级框架
function direct(url,frameid,isparent)
{
	if(!isparent || isparent == "" || isparent == "undefined")
	{
		if(frameid)
		{
			window.frames[frameid].location.href = url;
		}
		else
		{
			window.location.href=url;
		}
	}
	else
	{
		if(!frameid || frameid == "" || frameid == "undefined")
		{
			parent.window.location.href = url;
		}
		else
		{
			window.parent.frames[frameid].location.href = url;
		}
	}
}

//设定多长时间运行脚本
//参数 time 是时间单位是毫秒，为0时表示直接运行 大于0小于10毫秒将自动*1000
//参数 js 要运行的脚本
function eval_js(time,js)
{
	time = parseFloat(time);
	if(time < 0.01)
	{
		eval(js);
	}
	else
	{
		if(time < 10)
		{
			time = time*1000;
		}
		window.setTimeout(js,time);
	}
}

//编码网址
function url_encode(str)
{
	return transform(str);
}

function transform(s)
{
	var hex=''
	var i,j,t

	j=0
	for (i=0; i<s.length; i++)
	{
		t = hexfromdec( s.charCodeAt(i) );
		if (t=='25')
		{
			t='';
		}
		hex += '%' + t;
	}
	return hex;
}

function hexfromdec(num)
{
	if (num > 65535)
	{
		return ("err!");
	}
	first = Math.round(num/4096 - .5);
	temp1 = num - first * 4096;
	second = Math.round(temp1/256 -.5);
	temp2 = temp1 - second * 256;
	third = Math.round(temp2/16 - .5);
	fourth = temp2 - third * 16;
	return (""+getletter(third)+getletter(fourth));
}

function getletter(num) 
{
	if (num < 10) 
	{
		return num;
	}
	else
	{
		if (num == 10) { return "A" }
		if (num == 11) { return "B" }
		if (num == 12) { return "C" }
		if (num == 13) { return "D" }
		if (num == 14) { return "E" }
		if (num == 15) { return "F" }
	}
}

/*取得当前网址所在的目录，仅限后台*/
function site_url()
{
	var siteurl = window.location.href;
	//去除?后面的相关参数
	siteurl = siteurl.substring(7,siteurl.indexOf("?"));
	//切分 / 符号
	var sitearray = siteurl.split("/");
	var newurl = "http://";
	for(var i=0;i<(sitearray.length-1);i++)
	{
		newurl += sitearray[i]+"/";
	}
	return newurl;
}

/*Cookie管理*/
function get_cookie(name)
{
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0)
	{
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
			{
				end = document.cookie.length;
			}
			cookieValue = unescape(document.cookie.substring(offset, end));
		}
	}
	return cookieValue;
}

function set_cookie(cookieName,cookieValue,DayValue)
{
	var expire = "";
	var day_value=1;
	if(DayValue!=null)
	{
		day_value=DayValue;
	}
    expire = new Date((new Date()).getTime() + day_value * 86400000);
    expire = "; expires=" + expire.toGMTString();
	document.cookie = cookieName + "=" + escape(cookieValue) +";path=/"+ expire;
}

function del_cookie(cookieName)
{
	var expire = "";
    expire = new Date((new Date()).getTime() - 1 );
    expire = "; expires=" + expire.toGMTString();
	document.cookie = cookieName + "=" + escape("") +";path=/"+ expire;
}

//关闭浏览器错误调试错误
function kill_error()
{
	return true;
}

//去除数组中重复的值
Array.prototype.unique = function()
{
	var a = {};
	var len = this.length;
	for(var i=0; i<len; i++)
	{
		if(typeof a[this[i]] == "undefined")
		a[this[i]] = 1;
	}
	this.length = 0;
	for(var i in a)
	{
		this[this.length] = i;
	}
	return this;
}

//合并字符串
function join_str(str1,str2)
{
	if(str1 == "" && str2 == "" )
	{
		return false;
	}
	if(str1 == "")
	{
		return str2;
	}
	if(str2 == "")
	{
		return str1;
	}
	var string = str1 + "," +str2;
	var array = string.split(",");
	var i = 0;
	var n_array = new Array();
	for(var m=0;m<array.length;m++)
	{
		if(array[m] != "")
		{
			n_array[i] = array[m];
			i++;
		}
	}
	n_array.unique();
	var n_string = n_array.join(",");
	if(n_string)
	{
		return n_string;
	}
	else
	{
		return false;
	}
}

function encode_utf8(str)
{
	return EncodeUtf8(str);
}

function EncodeUtf8(s1)
{
	var s = escape(s1);
	var sa = s.split("%");
	var retV ="";
	if(sa[0] != "")
	{
		retV = sa[0];
	}
	for(var i = 1; i < sa.length; i ++)
	{
		if(sa[i].substring(0,1) == "u")
		{
			retV += Hex2Utf8(Str2Hex(sa[i].substring(1,5)));
			if(sa[i].length>5)
			{
				retV += sa[i].substring(5);
			}
		}
		else
		{
			retV += "%" + sa[i];
		}
	}
	return retV;
}
function Str2Hex(s)
{
	var c = "";
	var n;
	var ss = "0123456789ABCDEF";
	var digS = "";
	for(var i = 0; i < s.length; i ++)
	{
		c = s.charAt(i);
		n = ss.indexOf(c);
		digS += Dec2Dig(eval(n));
	}
	return digS;
}
function Dec2Dig(n1)
{
	var s = "";
	var n2 = 0;
	for(var i = 0; i < 4; i++)
	{
		n2 = Math.pow(2,3 - i);
		if(n1 >= n2)
		{
			s += '1';
			n1 = n1 - n2;
		}
		else
		{
			s += '0';
		}
	}
	return s;
}
function Dig2Dec(s)
{
	var retV = 0;
	if(s.length == 4)
	{
		for(var i = 0; i < 4; i ++)
		{
			retV += eval(s.charAt(i)) * Math.pow(2, 3 - i);
		}
		return retV;
	}
	return -1;
}
function Hex2Utf8(s)
{
	var retS = "";
	var tempS = "";
	var ss = "";
	if(s.length == 16)
	{
		tempS = "1110" + s.substring(0, 4);
		tempS += "10" +  s.substring(4, 10);
		tempS += "10" + s.substring(10,16);
		var sss = "0123456789ABCDEF";
		for(var i = 0; i < 3; i ++)
		{
			retS += "%";
			ss = tempS.substring(i * 8, (eval(i)+1)*8);
			retS += sss.charAt(Dig2Dec(ss.substring(0,4)));
			retS += sss.charAt(Dig2Dec(ss.substring(4,8)));
		}
		return retS;
	}
	return "";
}

//Layer类
var Layer=
{
	init:function(url,divw,divh,vLeft,vTop)
	{
		Layer.divw = divw>240 ? divw : 240;//弹出窗口的宽，最小为240
		Layer.divh = divh>170 ? divh : 170;//弹出窗口的高，最小为170
		Layer.content = url ? '<iframe width="'+Layer.divw+'px" height="'+Layer.divh+'px" frameborder="0" style="overflow-x:hidden;" src="'+url+'" id="qgLayerFrameId" name="qgLayerFrameId"></iframe>' : '<iframe width="'+Layer.divw+'px" height="'+Layer.divh+'px" frameborder="0" style="overflow:hidden;" src="about:blank"></iframe>';
		//判断居层的左右上下值
		if(vLeft && vLeft>=Layer.divw)
		{
			Layer.vLeft = vLeft-Layer.divw;
		}
		else
		{
			Layer.vLeft = (doc_type.clientWidth - Layer.divw)/2;
		}
		if(vTop && vTop<Layer.divh)
		{
			Layer.vTop = vTop;
		}
		else
		{
			Layer.vTop = (doc_type.clientHeight-Layer.divh)/2 + doc_type.scrollTop;
			if(divh == 312)
			{
				Layer.vTop = 10;
			}
		}
		Layer.screenConvert();
		Layer.dialogShow();
	},
	over:function()
	{
		Layer.screenOver();
		Layer.dialogOver();
	},/*关闭*/
	screenConvert:function()
	{
		var objScreen = getid("ScreenOver");
		if (!objScreen) var objScreen = document.createElement("div");
		objScreen.id = "ScreenOver";
		var oS = objScreen.style;
		var bgww=doc_type.offsetWidth;//网页可见区域宽度
		var bgwh=doc_type.scrollHeight; //滚动条的高度
		winHeight = doc_type.clientHeight;
		winWidth = doc_type.clientWidth;
		if(bgwh>winHeight)
		{
			winHeight=bgwh;
		}
		Layer.winWidth = winWidth;
		Layer.winHeight = winHeight;
		var s_style = "width:100%;height:"+winHeight+"px;";
		s_style += "display:block;left:0px;top:0px;";
		s_style += "position:absolute;z-index:50;";
		s_style += "background:#000;filter:alpha(opacity=45);";
		s_style += "opacity:0.45;";
		oS.cssText = s_style;
		Layer.objScreen = objScreen;
		document.body.appendChild(objScreen);
	},
	screenOver:function()
	{
		var objScreen = getid("ScreenOver");
		if (objScreen)
		{
			objScreen.style.display="none";
			document.body.removeChild(objScreen);
		}
		var this_select = document.getElementsByTagName("select");
		for(i=0;i<this_select.length;i++)
		{
			this_select[i].style.display = "";
		}
	},
	dialogShow:function()
	{
		var Tips=getid("qgLayerTips");
		if(!Tips){
			Tips=document.createElement("div");
			Tips.id="qgLayerTips";
			var Tipstyle=Tips.style;
			Tipstyle.position="absolute";
			Tipstyle.height = Layer.divh + "px";
			Tipstyle.width = Layer.divw + "px";
			Tipstyle.background="#FFF";
			Tipstyle.zIndex = "100";
			Tipstyle.top = Layer.vTop + "px";
			Tipstyle.left = Layer.vLeft + "px";
			Tipstyle.padding = "0";
		}else{
			Tips.style.display="";
		}//创建一个弹出框

		var content=getid("qgvContentMsg");/*提示框里的调用内容格式*/
		if(!content)
		content=document.createElement("div");
		content.id="qgvContentMsg";
		var cstyle=content.style;
		cstyle.margin="0px";
		cstyle.padding="0px";
		cstyle.width="100%";
		cstyle.zIndex = "90";
		var bottom_msg = "<div style='padding:2px auto;'><table width='100%' cellpadding='0' cellspacing='0'><tr><td height='20px'>&nbsp;附件管理中心</td><td align='right'>&nbsp;<img src='images/del.gif' border='0' onclick='Layer.over();' title='Close' align='absmiddle' style='cursor:pointer;'>&nbsp; &nbsp;</td></tr></table></div>";
		content.innerHTML=bottom_msg+"<div>"+Layer.content+"</div>";

		Tips.appendChild(content);
		document.body.appendChild(Tips);
		var this_select = document.getElementsByTagName("select");
		for(i=0;i<this_select.length;i++)
		{
			this_select[i].style.display = "none";
		}
	},
	dialogOver:function()
	{
		var Tips=getid("qgLayerTips");
		if(Tips)
		{
			Tips.style.display="none";
			document.body.removeChild(Tips);
		}
	}
}


//-------获取元素的纵坐标
function getTop(e)
{
	var offset=e.offsetTop;
	if(e.offsetParent!=null)
	{
		offset+=getTop(e.offsetParent);
	}
	return offset;
}
//-------获取元素的横坐标
function getLeft(e)
{
	var offset=e.offsetLeft;
	if(e.offsetParent!=null)
	{
		offset+=getLeft(e.offsetParent);
	}
	return offset;
}
